<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Echo</title>
  <link rel="stylesheet" href="//cdn.jsdelivr.net/normalize/3.0.1/normalize.min.css">
  <script src="/chatops/primus.js"></script>
  <style>
  body {
    padding: 50px
  }
  
  #output {
    width: 450px;
    height: 200px;
    display: block;
    border: 0;
    outline: 0;
    margin: 0 0 4px
  }
  
  #echo {
    width: 400px;
    height: 25px;
    font-size: 16px
  }
  
  button {
    border-radius: 5px;
    border: 0;
    background: #444;
    color: #FFF;
    padding: 6px
  }
  </style>
</head>

<body>
  <form id="write">
    <textarea id="output" readonly></textarea>
    <input placeholder="write message that should echo" id="echo" />
    <button type="submit">echo</button>
  </form>
  <script>
  var output = document.getElementById('output'),
    echo = document.getElementById('echo');
  //
  // Tell primus to create a new connect to the current domain/port/protocol
  //
  var primus = Primus.connect('http://chatops.uyundev.cn');
  //
  // Listen for incoming data and log it in our textarea.
  //
  primus.on('open', function (data) {
    console.log(data)
  });

  primus.on('data', function (data) {
    console.log(data)
  });

  primus.on('error', function (data) {
    console.log(data)
  });

  primus.on('close', function (data) {
    console.log(data)
  });

  var action = {
 "type":"message/create",
 "data":{
 "_id":"fake-2017-04-27T14:46:44.930Z-1",
 "_toId":"5722552d80bf42f8aa965c3445a43f5a",
 "_teamId":"a10adc3949ba59abbe56e057f20f88aa",
 "attachments":[
 
 ],
 "body":"kkk",
 "createdAt":"2017-04-27T14:46:44.930Z",
 "creator":{
 "isRobot":false,
 "unions":[
 
 ],
 "pys":[
 
 ],
 "from":"register",
 "pinyins":[
 
 ],
 "name":"lalal",
 "updatedAt":"2017-04-27T14:45:18.457Z",
 "isGuest":false,
 "__v":0,
 "avatarUrl":"/tenant/userimages/category2/a10adc3949ba59abbe56e057f20f88aa.png",
 "_id":"a10adc3949ba59abbe56e057f20f88aa",
 "preference":{
 "notifyOnRelated":false,
 "displayMode":"default",
 "emailNotification":true,
 "desktopNotification":true,
 "customOptions":{
 "hasGetReply":false,
 "needTalkAIReply":true
 },
 "updatedAt":"2017-04-17T02:32:32.165Z",
 "hasSentLoginMail":false,
 "hasShownTips":false,
 "muteWhenWebOnline":false,
 "__v":0,
 "pushOnWorkTime":false,
 "hasShownRichTextTips":false,
 "language":"zh",
 "timezone":"Asia/Shanghai",
 "_id":"a10adc3949ba59abbe56e057f20f88aa",
 "id":"a10adc3949ba59abbe56e057f20f88aa",
 "createdAt":"2017-04-17T02:32:30.911Z",
 "_latestTeamId":"a10adc3949ba59abbe56e057f20f88aa"
 },
 "id":"a10adc3949ba59abbe56e057f20f88aa",
 "createdAt":"2017-04-27T14:45:18.457Z",
 "email":"demo@uyunsoft.cn"
 },
 "icon":"normal",
 "isSystem":false,
 "tags":[
 
 ],
 "team":"",
 "updatedAt":"2017-04-27T14:46:44.930Z",
 "_creatorId":"a10adc3949ba59abbe56e057f20f88aa",
 "displayType":"text"
 }
}


  // Listen for submits of the form so we can send the message to the server.
  document.getElementById('write').onsubmit = function submit(e) {
    if (e && e.preventDefault) e.preventDefault();
    // Write the typed message.
    // primus.write(echo.value);
    action.data.body = echo.value
    primus.emit('message:create', action.data)

    echo.value = '';
  };
  </script>
</body>

</html>
